﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/table">
		<xsl:variable name="nodeCount" select="count(rows/row[1]/*)"/>
		<xsl:variable name="rowCount" select="count(rows/row)"/>
		<xsl:element name="sql">
			<xsl:for-each select="rows/row">
Insert Into <xsl:value-of select="/table/@name"/>
(<xsl:for-each select="*"><xsl:value-of select="name()"/><xsl:if test="position() &lt; $nodeCount">,</xsl:if></xsl:for-each>)
Values
(<xsl:for-each select="*">"<xsl:value-of select="."/>"<xsl:if test="position() &lt; $nodeCount">,</xsl:if></xsl:for-each>);
			</xsl:for-each>
		</xsl:element>
    </xsl:template>
</xsl:stylesheet>
